package com.jcy.jcyrxjava.timeselect;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jcy.jcyrxjava.R;

import java.util.List;

public class TimeAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mData;

    public TimeAdapter(Context mContext, List<String> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        View view;
        if (convertView == null) {
        // inflate出子项布局，实例化其中的图片控件和文本控件
            view = LayoutInflater.from(mContext).inflate(R.layout.set_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.text_content = view.findViewById(R.id.text_content);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            // 取出缓存
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.text_content.setText(mData.get(position));
        return view;
    }

    class ViewHolder {
        TextView text_content;
    }
}
